import java.util.Random;

public class test {
    static int sum1=0;
    static int sum2=0;
    public static void main(String[] args) throws InterruptedException {
        int[] n=new int[10000000];
        long startTime=System.currentTimeMillis();
        Random random=new Random();
        for (int i = 0; i <n.length ; i++) {
            n[i]=(random.nextInt(100)+1);//1-100
        }
        Thread t1=new Thread(()->{
            //偶数下标元素的和
            for (int i = 0; i <n.length ; i=i+2) {
                sum1=sum1+n[i];
            }
            System.out.println("线程1："+sum1);
        });
        t1.start();
        Thread t2=new Thread(()->{
            //偶数下标元素的和
            for (int i = 1; i <n.length ; i=i+2) {
                sum2=sum2+n[i];
            }
            System.out.println("线程1:"+sum2);
        });
        t2.start();

        t1.join();
        t2.join();
        long endTime=System.currentTimeMillis();
        System.out.println("结果："+(sum1+sum2));
        System.out.println("执行总时间："+(endTime-startTime));
    }
}
